package com.yanqu.road.server.cmd.union.cross.huaben;

import com.yanqu.road.pb.union.cross.UnionHuaBenProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.huaben.CrossUnionHuaBenMgr;
import com.yanqu.road.server.manger.UnionHuaBenServerGroupMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_UNION_HUA_BEN_GUAN_PU_RECORD_UPLOAD, desc = "上报关扑奖励公告")
public class CrossUnionHuaBenGuanPuHistoryRecordUploadCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        UnionHuaBenProto.UnionHuaBenGuanPuHistoryRecordUploadMsg syncMsg = UnionHuaBenProto.UnionHuaBenGuanPuHistoryRecordUploadMsg.parseFrom(packet.getBytes());
        for (UnionHuaBenProto.UnionHuaBenGuanPuHistoryRecordTemp temp : syncMsg.getRecordList()) {
            CrossUnionHuaBenMgr.addGuanPuRewardRecord(serverId, temp);
        }

        //同步增量到分组
        int groupId = UnionHuaBenServerGroupMgr.getGroupIdByServerId(serverId);
        for (Long sid : UnionHuaBenServerGroupMgr.getGroupServer(groupId)) {
            MessageHelper.sendPacket(sid, 0, YanQuMessageUtils.buildMessage(Protocol.S_CROSS_UNION_HUA_BEN_GUAN_PU_RECORD_SYNC_FROM_CROSS,
                    UnionHuaBenProto.UnionHuaBenGuanPuHistoryRecordSyncMsg.newBuilder().addAllRecord(syncMsg.getRecordList())));
        }
    }

    @Override
    public void sendData() {

    }
}
